/**
 *  This file is part of MunchLevel.
 *
 *  MunchLevel is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  MunchLevel is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with MunchLevel.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.munchlevel.util;

import com.gandulf.guilib.util.Debug;
import com.munchlevel.R;

/**
 * @author Ganymede
 * 
 */
public class Util {

	public static Integer getArrayId(String name) {
		return getId(R.array.class, name);
	}

	public static String capitalize(String s) {
		if (s == null || s.length() == 0)
			return s;
		return s.substring(0, 1).toUpperCase() + s.substring(1);
	}

	public static Integer getId(Class<?> clazz, String name) {
		Integer arrayId = null;
		try {
			arrayId = (Integer) clazz.getField(name).get(null);
		} catch (NoSuchFieldException e) {
			return null;
		} catch (Exception e) {
			Debug.error(e);
		}

		if (arrayId != null)
			return arrayId;
		else
			return null;
	}
}
